/*
 * Message queue class that is integral part of messaging system
 */


public class MessageQueue{

	/*maintain head and rear */
	private Node front;
	private Node rear;

	public Queue(){
		front = null;
		rear = null;
	}

	void enqueue(Node node){
		Node headTemp = new Node(value);
		headTemp.nextNode = head;
		head = headTemp;
	}

	int dequeue(){
		Node temp;
		temp = head;
		int value = 0;

		if(head == null){
			return -1;
		}

		if(temp.nextNode == null){
			value = temp.value;
			head = null;
			return value;
		}

		while(temp.nextNode.nextNode != null){
			temp = temp.nextNode;
		}

		value = temp.nextNode.value;
		temp.nextNode = null;

		return value;
	}

	void printQueue(){
		Node temp;
		temp = head;
		while(temp != null){
			System.out.println(temp.value);
			temp = temp.nextNode;
		}
	}
	
	/** test code */

	public static void main(String args[]){
		System.out.println("Test message queue \n");
	}

}


